#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums)
    {
        vector<int>::iterator itor;
        vector<int>::iterator next_itor;
        for (itor = nums.begin(); itor != nums.end();) {
            next_itor = itor + 1;
            while (*itor == *next_itor && next_itor != nums.end()) {
                //erase method return the itor after the deleted item
                next_itor = nums.erase(next_itor);
            }
            itor++;
        }
        return nums.size();
    }
    /* better way
    int removeDuplicates(vector<int>& nums){
        if (nums.size() == 0) return 0;
        int i = 0;
        for (int j = 1; j < nums.size(); j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }
    */
};

int main(int argc, char const* argv[])
{
    Solution temp;
    int a[10] = { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 };
    vector<int> nums(a, a + 10);
    temp.removeDuplicates(nums);
    return 0;
}